package com.micro.service.auth.server.model;

import javax.persistence.Entity;
import javax.persistence.Id;
import java.util.Date;

/**
* @Description: 端详情实体类
* @Author lvxiucai
* @create 17:04 2017/12/28 
* @return
*/
@Entity
public class OauthClientDetails {

    private Date createTime = new Date();
    private boolean archived = false;

    /**
    * 客户端ID
    */
    @Id
    private String clientId;
    /**
    * 客户端所能访问的资源id集合,多个资源时用逗号(,)分隔
    */
    private String resourceIds;

    /**
     * 用于指定客户端(client)的访问密匙
    */
    private String clientSecret;
    /**
     * Available values: read,write
     * 指定客户端申请的权限范围,可选值包括read,write,trust;若有多个权限范围用逗号(,)分隔
     */
    private String scope;

    /**
     * grant types include
     * "authorization_code", "password", "assertion", and "refresh_token".
     * Default value is "authorization_code,refresh_token".
     */
    private String authorizedGrantTypes = "authorization_code,refresh_token";

    /**
     * The re-direct URI(s) established during registration (optional, comma separated).
     */
    private String webServerRedirectUri;

    /**
     * Authorities that are granted to the client (comma-separated). Distinct from the authorities
     * granted to the user on behalf of whom the client is acting.
     * <p/>
     * For example: ROLE_USER
     */
    private String authorities;

    /**
    * @Description: 指定tocken 有效期
    * The access token validity period in seconds (optional).
    * If unspecified a global default will be applied by the token services.
    * @author lvxiucai
    * @create 9:40 2018/1/9
    * @last modify by [lvxiucai 9:40 2018/1/9 ]
    * @return
    */
    private Integer accessTokenValidity;

    /**
    * @Description: 指定refresh tocken 有效期
    * The refresh token validity period in seconds (optional).
    * If unspecified a global default will  be applied by the token services.
    * @author lvxiucai
    * @create 9:42 2018/1/9
    * @last modify by [lvxiucai 9:42 2018/1/9 ]
    * @return
    */
    private Integer refreshTokenValidity;

    /**
    * @Description: 扩展字段
    * @author lvxiucai
    * @create 14:07 2018/3/26 
    * @last modify by [lvxiucai 14:07 2018/3/26 ]
    * @return
    */
    private String additionalInformation;

    /**
     * The client is trusted or not. If it is trust, will skip approve step
     * default false.
     */
    private boolean trusted = false;

    public OauthClientDetails() {
    }
    public OauthClientDetails(String clientId) {
        this.clientId = clientId;
    }

    public boolean trusted() {
        return trusted;
    }

    public Date createTime() {
        return createTime;
    }

    public boolean archived() {
        return archived;
    }

    public String clientId() {
        return clientId;
    }

    public String resourceIds() {
        return resourceIds;
    }

    public String clientSecret() {
        return clientSecret;
    }

    public String scope() {
        return scope;
    }

    public String authorizedGrantTypes() {
        return authorizedGrantTypes;
    }

    public String webServerRedirectUri() {
        return webServerRedirectUri;
    }

    public String authorities() {
        return authorities;
    }

    public Integer accessTokenValidity() {
        return accessTokenValidity;
    }

    public Integer refreshTokenValidity() {
        return refreshTokenValidity;
    }

    public String additionalInformation() {
        return additionalInformation;
    }


    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder();
        sb.append("OauthClientDetails");
        sb.append("{createTime=").append(createTime);
        sb.append(", archived=").append(archived);
        sb.append(", clientId='").append(clientId).append('\'');
        sb.append(", resourceIds='").append(resourceIds).append('\'');
        sb.append(", clientSecret='").append(clientSecret).append('\'');
        sb.append(", scope='").append(scope).append('\'');
        sb.append(", authorizedGrantTypes='").append(authorizedGrantTypes).append('\'');
        sb.append(", webServerRedirectUri='").append(webServerRedirectUri).append('\'');
        sb.append(", authorities='").append(authorities).append('\'');
        sb.append(", accessTokenValidity=").append(accessTokenValidity);
        sb.append(", refreshTokenValidity=").append(refreshTokenValidity);
        sb.append(", additionalInformation='").append(additionalInformation).append('\'');
        sb.append(", trusted=").append(trusted);
        sb.append('}');
        return sb.toString();
    }

    public OauthClientDetails clientId(String clientId) {
        this.clientId = clientId;
        return this;
    }

    public OauthClientDetails clientSecret(String clientSecret) {
        this.clientSecret = clientSecret;
        return this;
    }

    public OauthClientDetails resourceIds(String resourceIds) {
        this.resourceIds = resourceIds;
        return this;
    }

    public OauthClientDetails authorizedGrantTypes(String authorizedGrantTypes) {
        this.authorizedGrantTypes = authorizedGrantTypes;
        return this;
    }

    public OauthClientDetails scope(String scope) {
        this.scope = scope;
        return this;
    }

    public OauthClientDetails webServerRedirectUri(String webServerRedirectUri) {
        this.webServerRedirectUri = webServerRedirectUri;
        return this;
    }

    public OauthClientDetails authorities(String authorities) {
        this.authorities = authorities;
        return this;
    }

    public OauthClientDetails accessTokenValidity(Integer accessTokenValidity) {
        this.accessTokenValidity = accessTokenValidity;
        return this;
    }

    public OauthClientDetails refreshTokenValidity(Integer refreshTokenValidity) {
        this.refreshTokenValidity = refreshTokenValidity;
        return this;
    }

    public OauthClientDetails trusted(boolean trusted) {
        this.trusted = trusted;
        return this;
    }

    public OauthClientDetails additionalInformation(String additionalInformation) {
        this.additionalInformation = additionalInformation;
        return this;
    }
}
